﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mono.Cecil;
using OpenReflect.Domain.Contracts;
using OpenReflect.Services.Builders;

//using Rhino.Mocks;

namespace OpenReflect.Test.BuilderTests
{
	/// <summary>
	///This is a test class for AssemblyReferenceBuilderTest and is intended
	///to contain all AssemblyReferenceBuilderTest Unit Tests
	///</summary>
	[TestClass]
	public class AssemblyReferenceBuilderTest
	{
		private AssemblyDefinition DefinitionUnderTest { get; set; }

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext { get; set; }

		#region Additional test attributes

		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		[TestInitialize]
		public void MyTestInitialize()
		{
			DefinitionUnderTest = AssemblyFactory.GetAssembly("System.Data.Linq.dll");
		}

		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//

		#endregion

		/// <summary>
		///A test for CreateAssemblyReferences
		///</summary>
		[TestMethod]
		public void should_return_correct_number_of_references()
		{
			IAssemblyReferenceBuilder target = new AssemblyReferenceBuilder();
			IList<IAssemblyReference> references = target.CreateAssemblyReferences(DefinitionUnderTest.MainModule);

			Assert.IsNotNull(references);
			Assert.AreEqual(8, references.Count);
		}

		[TestMethod]
		[Obsolete]
		public void should_return_correct_names_of_references_for_system_linq()
		{
			IAssemblyReferenceBuilder target = new AssemblyReferenceBuilder();
			IList<IAssemblyReference> references = target.CreateAssemblyReferences(DefinitionUnderTest.MainModule);
			bool nullDoesntExists = references.All(item => item != null);

			bool msCorlibExists = references.Any(item => item.Name == "mscorlib");
			bool systemExists = references.Any(item => item.Name == "System");
			bool coreExists = references.Any(item => item.Name == "System.Core");
			bool dataExists = references.Any(item => item.Name == "System.Data");
			bool serializationExists = references.Any(item => item.Name == "System.Runtime.Serialization");
			bool transactionExists = references.Any(item => item.Name == "System.Transactions");
			bool xmlExist = references.Any(item => item.Name == "System.Xml");
			bool linqExist = references.Any(item => item.Name == "System.Xml.Linq");

			Assert.IsTrue(nullDoesntExists);
			Assert.IsTrue(msCorlibExists);
			Assert.IsTrue(systemExists);
			Assert.IsTrue(coreExists);
			Assert.IsTrue(dataExists);
			Assert.IsTrue(serializationExists);
			Assert.IsTrue(transactionExists);
			Assert.IsTrue(xmlExist);
			Assert.IsTrue(linqExist);
		}
	}
}